﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;

using LIM.forms.uc_DanhMuc_PhongBan;
using LIM.controller;
using LIM.model;
using Telerik.WinControls.UI;

namespace LIM.forms
{
    public partial class radForm_DanhMuc_PhongBan : Telerik.WinControls.UI.RadForm
    {
        public radForm_DanhMuc_PhongBan()
        {
            InitializeComponent();            
        }
        public delegate void ListViewDoubleClick();
        public event ListViewDoubleClick OnRowChange;

        public tbl_DanhMuc_PhongBan SelectedEntity { set; get; }
        public SYSController _SYSController = new SYSController();
        public DanhMucPhongBanController controller = new DanhMucPhongBanController();
        private void radForm_DanhMuc_PhongBan_Load(object sender, EventArgs e)
        {
           // radListView1.DataSource = controller.LayDanhSach_PhongBan();
            loadData();
            uc_DanhMuc_PhongBan_ThongTinPhongBan uc_DanhMuc_PhongBan_ThongTinPhongBan = new uc_DanhMuc_PhongBan_ThongTinPhongBan();
            uc_DanhMuc_PhongBan_ThongTinPhongBan.Dock = DockStyle.Fill;
            this.radPageViewPage_ThongTinPhongBan.Controls.Add(uc_DanhMuc_PhongBan_ThongTinPhongBan);

            uc_DanhMuc_PhongBan_DanhSachNhanVien uc_DanhMuc_PhongBan_DanhSachNhanVien = new uc_DanhMuc_PhongBan_DanhSachNhanVien();
            uc_DanhMuc_PhongBan_DanhSachNhanVien.Dock = DockStyle.Fill;
            this.radPageViewPage_DanhSachNhanVien.Controls.Add(uc_DanhMuc_PhongBan_DanhSachNhanVien);

            uc_DanhMuc_PhongBan_ChiTieuKiemNghiem uc_DanhMuc_PhongBan_ChiTieuKiemNghiem = new uc_DanhMuc_PhongBan_ChiTieuKiemNghiem();
            uc_DanhMuc_PhongBan_ChiTieuKiemNghiem.Dock = DockStyle.Fill;
            this.radPageViewPage_ChiTieuKiemNghiem.Controls.Add(uc_DanhMuc_PhongBan_ChiTieuKiemNghiem);
        }

        void loadData()
        {
            radListView1.Items.Clear();
            foreach (tbl_DanhMuc_PhongBan item in controller.LayDanhSach_PhongBan())
            {
                ListViewDataItem items = new ListViewDataItem();
                items.Text = item.TenGoi;
                items.Tag = item.RowID;
                radListView1.Items.Add(items);
            }
            radListView1.SelectedIndex = 0;
        }
        private void radListView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.radListView1.CurrentItem.Tag != null)
            {
                SelectedEntity = controller.LayPhongBanByRowID(int.Parse(this.radListView1.CurrentItem.Tag.ToString()));
                if (OnRowChange != null)
                    OnRowChange();
            }

        }
        public void RefreshData()
        {
            //_SYSController.Refresh_tbl_DanhMuc_ThongTinNhanVien();
            //radForm_DanhMuc_PhongBan_Load(new object(), new EventArgs()); 
        }

        private void radMenuItem2_Click(object sender, EventArgs e)
        {
            radListView1.SelectedIndex = 0;
            SelectedEntity = new tbl_DanhMuc_PhongBan();
            if (OnRowChange != null)
                OnRowChange();
        }

        private void radMenuItem1_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

    }
}
